﻿Public Class ctrNhanVien

    Private Sub ShowTab()
        Dim i As Integer = frmMain.TabControl1.TabCount - 1
        frmMain.TabControl1.SelectTab(i)
    End Sub

    Private Function ExistsTab(ByVal str As String) As Integer
        For i = 0 To frmMain.TabControl1.TabCount() - 1 Step 1
            If (frmMain.TabControl1.TabPages(i).Text = str) Then
                Return i
            End If
        Next
        Return -1
    End Function

    Private Sub btnTiepNhan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTiepNhan.Click
        'effect
        btnTiepNhan.ForeColor = Color.White
        btnTiepNhan.BackColor = Color.Green
        btnTraCuu.ForeColor = Color.Green
        btnTraCuu.BackColor = Color.White
        btnPhanCong.ForeColor = Color.Green
        btnPhanCong.BackColor = Color.White
        btnBC_CV.ForeColor = Color.Green
        btnBC_CV.BackColor = Color.White
        btnChinhSuaNV.ForeColor = Color.Green
        btnChinhSuaNV.BackColor = Color.White

        Dim str As String = "Tiếp nhận nhân viên"
        If (ExistsTab(str) = -1) Then
            Dim tab As TabPage = New TabPage()
            frmMain.TabControl1.Controls.Add(tab)
            tab.Text = str

            Dim ctr As ctrTiepNhanNV = New ctrTiepNhanNV()
            tab.Controls.Add(ctr)
            ctr.Dock = DockStyle.Fill

            ShowTab()
        Else
            frmMain.TabControl1.SelectTab(ExistsTab(str))
        End If
    End Sub

    Private Sub btnTraCuu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTraCuu.Click
        'effect
        btnTiepNhan.ForeColor = Color.Green
        btnTiepNhan.BackColor = Color.White
        btnTraCuu.ForeColor = Color.White
        btnTraCuu.BackColor = Color.Green
        btnPhanCong.ForeColor = Color.Green
        btnPhanCong.BackColor = Color.White
        btnBC_CV.ForeColor = Color.Green
        btnBC_CV.BackColor = Color.White
        btnChinhSuaNV.ForeColor = Color.Green
        btnChinhSuaNV.BackColor = Color.White

        Dim str As String = "Tra cứu nhân viên"
        If (ExistsTab(str) = -1) Then
            Dim tab As TabPage = New TabPage()
            frmMain.TabControl1.Controls.Add(tab)
            tab.Text = str

            Dim ctr As ctrTraCuuNV = New ctrTraCuuNV()
            tab.Controls.Add(ctr)
            ctr.Dock = DockStyle.Fill

            ShowTab()
        Else
            frmMain.TabControl1.SelectTab(ExistsTab(str))
        End If
    End Sub

    Private Sub btnBC_CV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBC_CV.Click
        'effect
        btnTiepNhan.ForeColor = Color.Green
        btnTiepNhan.BackColor = Color.White
        btnTraCuu.ForeColor = Color.Green
        btnTraCuu.BackColor = Color.White
        btnPhanCong.ForeColor = Color.Green
        btnPhanCong.BackColor = Color.White
        btnBC_CV.ForeColor = Color.White
        btnBC_CV.BackColor = Color.Green
        btnChinhSuaNV.ForeColor = Color.Green
        btnChinhSuaNV.BackColor = Color.White

        Dim str As String = "Bằng cấp - Chức vụ"
        If (ExistsTab(str) = -1) Then
            Dim tab As TabPage = New TabPage()
            frmMain.TabControl1.Controls.Add(tab)
            tab.Text = str

            Dim ctr As ctrChucVu_BangCap = New ctrChucVu_BangCap()
            tab.Controls.Add(ctr)
            ctr.Dock = DockStyle.Fill

            ShowTab()
        Else
            frmMain.TabControl1.SelectTab(ExistsTab(str))
        End If
    End Sub

    Private Sub btnPhanCong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPhanCong.Click
        'effect
        btnTiepNhan.ForeColor = Color.Green
        btnTiepNhan.BackColor = Color.White
        btnTraCuu.ForeColor = Color.Green
        btnTraCuu.BackColor = Color.White
        btnPhanCong.ForeColor = Color.White
        btnPhanCong.BackColor = Color.Green
        btnBC_CV.ForeColor = Color.Green
        btnBC_CV.BackColor = Color.White
        btnChinhSuaNV.ForeColor = Color.Green
        btnChinhSuaNV.BackColor = Color.White

        Dim str As String = "Phân công nhân viên"
        If (ExistsTab(str) = -1) Then
            Dim tab As TabPage = New TabPage()
            frmMain.TabControl1.Controls.Add(tab)
            tab.Text = str

            Dim ctr As ctrPhanCongNV = New ctrPhanCongNV()
            tab.Controls.Add(ctr)
            ctr.Dock = DockStyle.Fill

            ShowTab()
        Else
            frmMain.TabControl1.SelectTab(ExistsTab(str))
        End If
    End Sub

    Private Sub btnChinhSuaNV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChinhSuaNV.Click
        'effect
        btnTiepNhan.ForeColor = Color.Green
        btnTiepNhan.BackColor = Color.White
        btnTraCuu.ForeColor = Color.Green
        btnTraCuu.BackColor = Color.White
        btnPhanCong.ForeColor = Color.Green
        btnPhanCong.BackColor = Color.White
        btnBC_CV.ForeColor = Color.Green
        btnBC_CV.BackColor = Color.White
        btnChinhSuaNV.ForeColor = Color.White
        btnChinhSuaNV.BackColor = Color.Green

        Dim str As String = "Chỉnh sửa nhân viên"
        If (ExistsTab(str) = -1) Then
            Dim tab As TabPage = New TabPage()
            frmMain.TabControl1.Controls.Add(tab)
            tab.Text = str

            Dim ctr As ctrChinhSuaNV = New ctrChinhSuaNV()
            tab.Controls.Add(ctr)
            ctr.Dock = DockStyle.Fill

            ShowTab()
        Else
            frmMain.TabControl1.SelectTab(ExistsTab(str))
        End If
    End Sub
End Class
